
export const checkWaybillV1 = (multiplequerywaybillno,cb)=>{
  let waybill = multiplequerywaybillno;
  if(null==waybill||waybill.length==0){
    if(cb){
      cb();
    }
    return '';
  }
  let waybillreg = /^\d{8,10}$/,
    waybillreg2 = /^\d{14}$/,
    waybillreg3 = /^[a-zA-Z][a-zA-Z0-9]+$/;
  let r = waybill.match(waybillreg),
    r2 = waybill.match(waybillreg2),
    r3 = waybill.match(waybillreg3);
  if(r3){
    return 'DD';
  }
  if(r2 || r){
    return 'YD';
  }
  return 'QT';
};


export const trimKG = (str)=>{
  return str.replace(/(^\s*)|(\s*$)/g, "");
}

export const substrWaybillNo = (e)=>{
  let str = e.substring(0, 3)+" "+e.substring(3, 6)+" "+e.substring(6);
  return str;
};

export const setWaybillNoMul = (multiplequerywaybillno)=>{
  let abccss = multiplequerywaybillno;
  if(multiplequerywaybillno.length>0){
    abccss =   substrWaybillNo(multiplequerywaybillno)
  }
  $(".csssuper .mulwbn").html(abccss);
};

//获取样式
export const getStyle = (obj,attr)=>{    //获取非行间样式，obj是对象，attr是值
  if(obj){
    if(obj.currentStyle){   //针对ie获取非行间样式
      return obj.currentStyle[attr];
    }else{
      return getComputedStyle(obj,false)[attr];   //针对非ie
    }
  }

};
/*控制文字显示长度*/
export const controlLength = (str, len)=>{
  if (str.length > len) {
    return str.substr(0, len - 1) + "....";
  } else {
    return str;
  }
};

/* selemenuboxCom组件的查询通讯录*/
export const checkPeople = (string)=>{
  var checkPeopleString = string;
    if(null==checkPeopleString||checkPeopleString.length==0)
    {
        return 'KB';
    }
    var deptworkcode = /^\d{6}$/,
    	deptmobile = /^\d{11}$/;
    var r = checkPeopleString.match(deptworkcode),
        r2 = checkPeopleString.match(deptmobile);
    if(null != r){
    	return 'GH';
    }else if((null != r2)){
    	return 'SJ';
    }else{
    	return 'XM';
    }
};

export const reWidth = ()=>{
  let linkModule = document.querySelectorAll('.link-module');
  let w = Number(getStyle(document.querySelectorAll('.col-link')[0],'width'));
  for(let i = 0;i< this.num;++i){
    linkModule[i].style.width = Math.floor( (w-20*(this.num-1))/this.num)+ 'px'
  }
};

// 找到当前元素指定父级
export const getFarther = (strF,target)=>{
  let el;
  if(target.classList){
    if(target.classList.contains(strF)){
      el = target;
    }else{
      el = getFarther(strF,target.parentNode);
    }
  }
  if(el){
    return el;
  }
};

export const getUrlQueryValue = (name)=>{
  let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  let r = window.location.search.substr(1).match(reg);
  if (r != null) {
    return decodeURIComponent(r[2]);
  }
  return null;
};

export const queryMenus = (keyword, successCallback)=>{
  let len = allMenus.length;
  let menusOfQuery = [];
  //输入空格后keyword.trim()为"",防止indexOf匹配
  if(keyword.trim() !== ""){
    for(let i=0;i<len;i++){
      if(allMenus[i].rootFunctionCode != null){
        //根据关键字来匹配
        if(allMenus[i].uumsFunction.functionName.indexOf(keyword.trim()) >= 0){
          menusOfQuery.push(allMenus[i]);
          if(menusOfQuery.length >= 20){
            break;
          }
        }
      }
    }
  }
  //根据菜单长度从小到大排序
  menusOfQuery.sort(function(a,b){
    return a.uumsFunction.functionName.length - b.uumsFunction.functionName.length;
  });
  if (successCallback) {
    successCallback(menusOfQuery);
  }
};
